/*
 *Welcome leaning gulp.
 */
var gulp = require('gulp'),
    minifycss = require('gulp-minify-css'),  //CSS压缩
    concat = require('gulp-concat'),         // 文件合并
    uglify = require('gulp-uglify'),         //js压缩插件
    rename = require('gulp-rename'),         // 重命名
    del = require('del');                    // 文件删除

gulp.task('default',function(){
    gulp.start('clean', 'minifycss', 'minifyjs');
});

/**
 * 测试更换名字
 */
gulp.task('rename', function(){
   gulp.src('src/1.js')
       .pipe(uglify())
       .pipe(rename('1.min.js'))
       .pipe(gulp.dest('ldy'));
});

/**
 * 测试压缩
 */
gulp.task('min-uglify', function(){
    gulp.src('src/**/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('dist/js'));
});

/**
 * 压缩css文件
 */
gulp.task('minifycss', function(){
   gulp.src('src/*.css')
       .pipe(minifycss())
       .pipe(gulp.dest('minified/css'));
});

/**
 * 压缩js合并到一个文件中
 */
gulp.task('minifyjs', function(){
   gulp.src('src/*.js')
       .pipe(concat('main.js'))
       .pipe(gulp.dest('minified/js'))
       .pipe(rename({suffix: '.min'}))
       .pipe(uglify())
       .pipe(gulp.dest('minified/js'));
});
/**
 * 清除文件
 */
gulp.task('clean', function(cb){
   del(['minified/js', 'minified/css'], cb);
});
